import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 04 - 16
 * Time: 16:32
 */
public class test7 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int k = 0;
        while((k = m % n) != 0){
            m = n;
            n = k;
        }
        System.out.println(n);
    }
}
